<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script type="text/javascript">
    function deletePro(obj){
      var tmp = confirm("是否确认删除");
      if(tmp){
        var tabObj = document.getElementById("mytable");
        // tabObj.removeChild(obj.parentNode.parentNode);
        console.log(tabObj.lastChild);
        tabObj.lastChild.removeChild(obj.parentNode.parentNode);
      }
    }
    function addPro(){
      var tabObj = document.getElementById("mytable");
      var trObj = document.createElement("tr");
      trObj.innerHTML="<td>3</td><td>理想</td><td>￥25</td><td><a>删除</a></td>";
      tabObj.appendChild(trObj);
      document.getElementById("dianwo").onclick=function(){
        alert("点我干啥");
      }
    }
    function checkAll(obj){
      var checkBoxs = document.getElementsByName("trdata");
      for(var i=0;i<checkBoxs.length;i++){
        checkBoxs[i].checked=obj.checked;
      }
    }
    function checkItem(){
      var checkBoxs = document.getElementsByName("trdata");
      var isChecked=true;//全选是否要选中
      for(var i=0;i<checkBoxs.length;i++){
        if(!checkBoxs[i].checked){
          isChecked = false;
          break;
        }
      }
      document.getElementById("all").checked=isChecked;
    }
  </script>
</head>
<body>
  <input type="button" value="点我" id="dianwo"/>
  <table border="1" align="center" id="mytable">
    <tr>
      <td><input type="checkbox" id="all" onchange="checkAll(this)"/></td>
      <td>编号</td><td>商品名</td><td>价格</td><td>操作</td></tr>
    <tr>
      <td><input type="checkbox" name="trdata" onclick="checkItem()"/></td>
      <td>1</td><td>su7</td><td>￥21</td><td><a href="javascript:void(0)" onclick="deletePro(this)">删除</a></td></tr>
    <tr>
      <td><input type="checkbox" name="trdata" onclick="checkItem()"/></td>
      <td>2</td><td>model Y</td><td>￥35</td><td><a>删除</a></td></tr>
  </table>
  <input type="button" onclick="addPro()" value="新增"/>
</body>
</html>